$().ready(function() {

});
function tipoftheday(){

	html='';
	html+='<div class="tipofday-bg">';
		html+='<div class="wrapper-tip-of-the-day">';
		html+='<div class="tip-of-the-day">';
			html+='<div class="text-tipoftheday"></div>';
				html+='<i class="clearfix"></i>';
				html+='<div class="img-tipoftheday-wrapper">';
					html+='<div class="img-tipoftheday"></div>';
				html+='</div>';
			html+='</div>';
		html+='</div>';
	html+='</div>';
	$('.box-two-content').html(html);
	$('.box-two .title span').text("Tip of the Day");
	switchwindow('tipoftheday');
	num_left_days();
}
function tipoftheday_nav(){
	var chk_log = $.cookie('chk_log');	
	if(chk_log==1){	
		html='';
		html+='<div class="tipofday-bg">';
			html+='<div class="wrapper-tip-of-the-day">';
			html+='<div class="tip-of-the-day">';
				html+='<div class="text-tipoftheday"></div>';
					html+='<i class="clearfix"></i>';
					html+='<div class="img-tipoftheday-wrapper">';
						html+='<div class="img-tipoftheday"></div>';
					html+='</div>';
				html+='</div>';
			html+='</div>';
		html+='</div>';
		$('.box-two-content').html(html);
		$('.box-two .title span').text("Tip of the Day");
		switchwindow_no_animate('tipoftheday');
		num_left_days();
	}
}

function num_left_days(){
	var ndays = 280;
	var dateConceptionDate = $.cookie('dateConceptionDate');
	cdate = dateConceptionDate.split('-');
	var date =new Date(cdate[0], cdate[1]-1,cdate[2]);
	
	nmonths = ndays/30.4166666667;// get 9 months
	nConceptionDate = new Date(cdate[0], cdate[1]-1,cdate[2]);// get date of conception
	
	xfunc = "countdown/get_date";
	data_sent = {};
	
	$.ajax({ 
		type: "POST", // request type POST
		url: base_url+xfunc, // post to PHP file
		data: data_sent, // request send to PHP file
		dataType:'json',
		success: function(result){ // result = return from php request		
			var dd = result.dd;
			var mm = result.mm;
			var yyyy = result.yyyy;		
			
			var nmdays = Math.round(((new Date(yyyy, mm-1,dd)-nConceptionDate))/86400000); // get due - now

			$('#intLeftDays').val(nmdays);
			//console.log(nmdays);
		}
	});		
	get_tipoftheday();
}
function get_tipoftheday(){		
	var leftdays = $('#intLeftDays').val();
	xfunc = "tipoftheday/get_tipoftheday";
	data_sent = {
			'intNumDays':leftdays
	};
	
	$.ajax({ 
		type: "POST", // request type POST
		url: base_url+xfunc, // post to PHP file
		data: data_sent, // request send to PHP file
		dataType:'json',
		success: function(result){ // result = return from php request
			if(result!=0){
				$('.text-tipoftheday').html(result.strNote);
				$('.text-tipoftheday').css({
					'font-size':result.intFontSize+'px'
				});		
				$('.img-tipoftheday').html('<img src="'+base_url+'assets/uploaded/img/thumbnail/'+result.strImgLink+'">')
			}
		}
	});		
}
